import React, { Component } from 'react'
import { Suspense } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { RouterItem } from "../types/router.d"
interface INPROPS{
  routes:RouterItem[]
}
export class routerView extends Component<INPROPS> {
  render() {
    const {routes}=this.props
    return (
      <div>
        <Suspense fallback={<div>加载中</div>}>
          <Switch>
          {
          routes && routes.map((item, index) => {
            return <Route key={index} path={item.path} render={(props) => {
              return item.to?<Redirect to={item.to}></Redirect>:<item.component {...props} children={item.children}></item.component>
            }}></Route>
          })
        }
        </Switch>
    </Suspense>
      </div>
    )
  }
}

export default routerView